package baiqitun.stupro.security.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 系统密码加密工具，用户认证时需要由先前端进行一次MD5加密
 * @author kedaji
 */
public class StuproPasswordEncoder implements PasswordEncoder {
    private PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    @Override
    public String encode(CharSequence rawPassword) {
        return encodeRule(rawPassword);
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return encodeRule(rawPassword).equals(encodedPassword);
    }

    private String encodeRule(CharSequence charSequence){
        return passwordEncoder.encode(charSequence);
    }
}
